#!/bin/bash
set -euo pipefail

SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"

function exit_and_fail() {
   echo "❌ Test Failed! Found a markdown file with spelling errors."
   exit 1
}
trap exit_and_fail INT ERR TERM

docker buildx build --load -t misspell -f $SCRIPTPATH/spellcheck-Dockerfile $SCRIPTPATH/
docker run -i --rm -v $SCRIPTPATH/../../:/app misspell /bin/bash -c 'find /app/ -type f -name "*.md" -not -path "build" | grep -v "/build/" | xargs misspell -error -debug'
echo "✅ Markdown file spell check passed!"